package com.longrise.android.byjk.plugins.hra.hratabthird;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.common.UrlConstants;
import com.longrise.android.byjk.plugins.hra.hratabfirst.OrderPlaceChildBean;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerFather;
import com.longrise.common.datasource.remote.LoadDataManager;

import java.util.List;

/**
 * Created by Administrator on 2018/1/9.
 * 预约改签presenter
 */

public class HraOrderEndorsePresenter extends HraOrderEndorseContract.Presenter {

    public static final String TAG = "HraOrderEndorsePresenter";
    private List<OrderPlaceChildBean> mParentBeanList ;

    @Override
    protected void init() {

    }

    //上传检测人信息到服务器
    @Override
    public void uploadCheckInfo(EntityBean bean) {
        mView.setBtnEnable(false);
        EntityBean bean1 = new EntityBean();
        bean1.set("bean", bean);
        LoadDataManager.getInstance().callService2(null, UrlConstants.BaseUrl, "hra_modifyMyEndorseCustomer", bean1, new LoadDataManager.OnRequestCallListener2() {

            @Override
            public void onSuccess(String key, String service, Object result) {
                try {
                    clientParse(result);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }



            @Override
            public void onFinished(String key, String service) {
                mView.setBtnEnable(true);
            }

            @Override
            public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {

            }

        });
    }

    private void clientParse(Object result){
        EntityBean bean = (EntityBean) result;
        int state = bean.getInt("resultstate");
        if (state == 1) {
            mView.showToast("改签成功");
            mView.start2DetailActivity();
        } else {
            mView.showToast(bean.getString("resultdesc"));
        }
    }

    //获取可预约时间段,库存
    @Override
    public void getTimeslotData(String storeId,String bespeakdate) {

        EntityBean bean = new EntityBean();
        bean.set("storeid", storeId);
        bean.set("bespeakdate", bespeakdate);
        EntityBean bean1 = new EntityBean();
        bean1.set("bean", bean);
        LoadDataManager.getInstance().callService2(null, UrlConstants.BaseUrl, "hra_getTimeslot", bean1, new LoadDataManager.OnRequestCallListener2() {

            @Override
            public void onSuccess(String key, String service, Object result) {
                try {
                    EntityBean bean = (EntityBean) result;
                    int resultstate = bean.getInt("resultstate");
                    if(resultstate == 1){
//                        parseDate(bean);
                        mView.refreshStockData(bean);
                    }else {
                        mView.showToast(bean.getString("resultdesc"));
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }


            @Override
            public void onFinished(String key, String service) {

            }

            @Override
            public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {

            }

        });
    }

    //上传修改时间信息
    @Override
    public void uploadEndorseTimeInfo(EntityBean bean) {
        mView.setBtnEnable(false);
        EntityBean bean1 = new EntityBean();
        bean1.set("bean", bean);
        LoadDataManager.getInstance().callService2(null, UrlConstants.BaseUrl, "hra_modifyMyEndorseStore", bean1, new LoadDataManager.OnRequestCallListener2() {

            @Override
            public void onSuccess(String key, String service, Object result) {
                try {
                    clientParse(result);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFinished(String key, String service) {
                mView.setBtnEnable(true);
            }

            @Override
            public void onError(String key, String service, LoadDataManagerFather.ResultType resultType) {

            }

        });
    }
}
